package com.qf.controller;

import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.pojo.DtsAdmin;
import com.qf.service.AdminService;
import com.qf.service.AdminUserService;
import com.qf.util.ResponseUtil;

import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping("/admin")
@Slf4j
public class AdminUserController {

    @Autowired
    AdminUserService adminUserService;

    @Autowired
    AdminService adminService;


    @RequiresPermissions("admin:admin:list")
    @RequiresPermissionsDesc(menu = { "系统管理", "管理员管理" }, button = "查询")
    @GetMapping("/admin/list")

    public Object list(
            @RequestParam(value = "page",required = false, defaultValue = "1") Integer page,
            @RequestParam(value = "limit",required = false, defaultValue = "20")Integer limit ,
            @RequestParam(value = "sort",required = false, defaultValue = "add_time") String sort,
            @RequestParam(value = "order",required = false, defaultValue = "desc")String order,
            String username) {

        Map<String,Object> data = adminUserService.findPage(page, limit, sort, order, username);
        return ResponseUtil.ok(data);
    }
    @RequiresPermissions("admin:admin:create")
    @RequiresPermissionsDesc(menu = { "系统管理", "管理员管理" }, button = "添加")
    @PostMapping("/admin/create")
    public Object creatAdmin(@RequestBody DtsAdmin admin){



        adminService.insert(admin);
        return ResponseUtil.ok(admin);
    }
    @RequiresPermissions("admin:admin:update")
    @RequiresPermissionsDesc(menu = { "系统管理", "管理员管理" }, button = "编辑")
    @PostMapping("/admin/update")

    public Object updateAdmin(@RequestBody DtsAdmin admin){



        adminService.update(admin);
        return ResponseUtil.ok(admin);
    }

    @RequiresPermissions("admin:admin:delete")
    @RequiresPermissionsDesc(menu = { "系统管理", "管理员管理" }, button = "删除")
    @PostMapping("/admin/delete")

    public Object delete(DtsAdmin admin){

        adminService.delete(admin);

        return ResponseUtil.ok();

    }
}
